﻿#pragma once
#include <string>
#include <vector>
#include "cybertron/core/Log.hpp"
#include "cybertron/core/logServer.hpp"
#include "cybertron/sensor/util/SensorConfigUtil.hpp"
#include "Node/Agent.pb.h"
#include "SimOneIOStruct.h"
#include "CybertronBridgeIO.hpp"
CYBERTRON_BEGIN

class BridgeConfig
{
public:
	void clear();
	bool loadConfig(Agent::WorkNodeRegisterRet* args, CybertronBridgeIO*p );

	std::string getOD() { return mOD; }
	std::string getODUrl() { return mODUrl; }
	std::string getODMd5() { return mODMd5; }

	std::string getStartScriptPath(std::string hostVehicle);
	std::string getEndScriptPath(std::string hostVehicle);

	static BridgeConfig& getInstance();
    std::string getTaskId() { return mTaskId; }

	std::string runMode = "manual";
	std::string simulinkType = "opened";
	std::string simulinkPath = "";
	std::string controlLevel = "AutoDrive";

	int vehicleId() const { return mHostVehicleId; }
	int getVehicleHz() { return mHostVehicleHz; }
	struct NodeInstance
	{
		int instanceId = 0;
		std::string ip;
		int port = 0;
		bool valid = false;
		ESimOne_Node_Type type = ESimOne_Node_Type_Vehicle;
		std::string alias;
		std::string friendlyId;
		int hz = 60;
	};
	struct CustomizationModule
	{
		std::string url;
		std::string suffix;
		std::string entry;
		std::string platform;
		std::string target;
		std::string langType;
		std::string interpretedScript;
	};
	struct HostVehicleConfig
	{
		std::string vehicleId = "-1";
		int vehicleHZ = 60;
		bool driverSet = false;
		bool isDriverAssited = false;
		//int caseStatus;
		int simOneAPITotalCount = 0;
		int simOneAPICurCount = 0;
		bool bWaitSimOneAPI = false;
		std::string startScriptPath;
		std::string endScriptPath;
		std::vector<NodeInstance> nodes;
		SimOne_Data_WayPoints wayPoints;
		SimOne_Data_SensorConfigurations sensorConfigurations;

		bool bIsCustomModule = false;
		CustomizationModule customModule;
		SensorGpsImuConfig	sensorGPSImuConfig;
	};
	std::map<std::string, HostVehicleConfig> getHostVehicleConfig() { return mHostVehicleConfigDataMap; };
	std::vector<NodeInstance> *nodes(std::string hostVehicle);
	const SensorGpsImuConfig &sensorGpsImuConfig(std::string hostVehicle);
	const SimOne_Data_Environment& sensorWeatherConfig() const { return mWeatherConfig; }
	SimOne_Data_SensorConfigurations* SensorConfigurations(std::string hostVehicle);
	SimOne_Data_WayPoints* wayPointsConfig(std::string hostVehicle);

	SimOne_Data_Map* getHDMapInfo()  { return &mHDMapInfo; }
	SimOne_Data_CaseInfo* getCaseInfo() { return &mCaseInfo; }
	int getCaseStatus() { return mCaseStatus; }
	bool IsGetTask() { return mbGetTask; }
	void sensorWeatherConfig(const SimOne_Data_Environment& config) { mWeatherConfig = config; }

	bool isDriverSet(std::string hostVehicle);
	bool isDriverAssited(std::string hostVehicle);

	CustomizationModule* customizationModuleConf(std::string hostVehicle);

	bool SetEnvironment(SimOne_Data_Environment* pWeatherConfig) {
		memcpy(&mWeatherConfig, pWeatherConfig, sizeof(SimOne_Data_Environment));
		return true;
	}
	void SetCaseStatus(int status) {
		mCaseStatus = status;
	}
	void AddSimOneAPICount(std::string hostVehicle);
	bool IsWaitSimOneAPI(std::string hostVehicle);
	int GetSimOneAPITotalCount(std::string hostVehicle);
private:
	BridgeConfig();
	~BridgeConfig();

	void zeroMembers();

	std::string mOD;
	std::string mODUrl;
	std::string mODMd5;

	static std::string mSensorCameraName;
	static std::string mSensorObjectBasedCameraName;
	static std::string mSensorLidarName;
	static std::string mSensorObjectBasedLidarName;
	static std::string mSensorPerfectPerception;
	static std::string mSensorIMU_GPSName;
	static std::string mSensorUltrasonicRadarName;
	static std::string mSensorAllUltrasonicRadarName;
	static std::string mSensorRadarName;
	static std::string mSensorObjectBasedRadarName;
	static std::string mSensorV2XName;
	static std::string mSensorFusionName;

	SimOne_Data_Environment mWeatherConfig;
	SimOne_Data_Map mHDMapInfo;
	SimOne_Data_CaseInfo mCaseInfo;
	int mCaseStatus;
	bool mbGetTask;
	std::string mTaskId;

	int mHostVehicleId;
	int mHostVehicleHz;

	std::map<std::string, HostVehicleConfig> mHostVehicleConfigDataMap;
};

CYBERTRON_END
